var app =getApp()
Page({
  data: {
    url : {
      getZanProduct: app.url.baseUrl + "/product/myGoodProduct",
    },
    products : [],
    isPage : true,
    pageNumber : -1,
  },
  onLoad: function () {
    this.getZanProduct()
  },
  getZanProduct : function(){
    if(!this.data.isPage){
     //提示
      return
    }
    var that = this
    var products = this.data.products
    app.ajax(this.data.url.getZanProduct,{pageNumber:this.data.pageNumber+1},function(res){
      var d = res.data
      var b = false
      var pageNum = that.data.pageNumber
      if(d.code == 2000 && d.data.length == 20){
        b = true
        pageNum+=1;
      }
      for(var i = 0;i<d.data.length;i++){
          var obj = d.data[i]
          products.push(obj)
      } 
      that.setData({ products: products, isPage: b, pageNumber: pageNum})
    })
  },
  onReachBottom:function(){
    this.getZanProduct()
  },
  shopInfo:function(e){
    var shopId = e.currentTarget.dataset.shopid
    wx.navigateTo({
      url: '../info/info?id='+shopId
    })
  },
  refreshData: function () {
    //初始化数据
    this.setData({ pageNumber: -1, products: [], isPage: true });
    this.getZanProduct()
  }
})

